package com.quanquan.store.service;

import com.quanquan.store.entity.BannerAdsence;
import com.quanquan.store.repository.BannerAdsenceRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import utils.DateUtils;
import utils.UUIDGenerator;

import java.util.Date;
import java.util.List;

/**
 * @ClassName:BannerBannerTypeService
 * @Description:TODO
 * @Author:xiongjunbao
 * @Date:2019/3/14 10:40
 * @Version 1.0
 */
@Service
public class BannerAdsenceService {

    @Autowired
    private BannerAdsenceRepository bannerAdsenseRepository;

    /**
     * 绑定banner和广告位
     *
     * @param bannerId
     * @param adsenceId
     * @return
     */
    public boolean saveBannerAdsence(String adsenceId,String bannerId){
        Date date = new Date();
        BannerAdsence bannerAdsense = new BannerAdsence();
        bannerAdsense.setId(UUIDGenerator.getUUID());
        bannerAdsense.setCreateTime(DateUtils.dateToString(date, DateUtils.TIMESTAMP));
        bannerAdsense.setUpdateTime(DateUtils.dateToString(date, DateUtils.TIMESTAMP));
        bannerAdsense.setStatusShow(0);
        bannerAdsense.setStatusRemove(0);
        bannerAdsense.setBannerId(bannerId);
        bannerAdsense.setAdsenceId(adsenceId);
        bannerAdsenseRepository.saveAndFlush(bannerAdsense);
        return true;
    }

    /**
     * 根据广告位类型找到对应banner
     *
     * @param adsenceId
     * @return
     */
    public List<BannerAdsence> queryByAdsenceId(String adsenceId){
        List<BannerAdsence> bannerAdsense =  bannerAdsenseRepository.queryByAdsenceId(adsenceId);
        return bannerAdsense;
    }

    /**
     * 查找banner对应的广告位
     *
     * @param bannerId
     * @return
     */
    public List<BannerAdsence> queryByBannerId(String bannerId){
        List<BannerAdsence> bannerAdsense =  bannerAdsenseRepository.queryByBannerId(bannerId);
        return bannerAdsense;
    }

}
